﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class SkillImprovement
    {
        public void ImportList(List<Classes.SkillImprovement> SkillImprovementList)
        {
            var mdb = new MedregDBDataContext();

            var sSerSpec = new Classes.SertificateSpeciality();
            var SerSpec = new SertificateSpeciality();
            SerSpec.ImportList(sSerSpec.getSertificateSpecialityList(SkillImprovementList));

            var sEdInst = new Classes.EducationInstitution();
            var EdInst = new EducationInstitution();
            EdInst.ImportList(sEdInst.getEducationInstitutionList(SkillImprovementList));


            foreach (Classes.SkillImprovement skillImprovement in SkillImprovementList)
            {
                var skillImprovement1 = new SkillImprovement
                {
                    
                    Organisation = skillImprovement.Organisation.ID,
                    EducationSpeciality = skillImprovement.EducationSpeciality.ID,
                    Cycle = skillImprovement.Cycle,
                    Hours = skillImprovement.Hours,
                    Year = skillImprovement.Year,
                    DiplomaSerie = skillImprovement.DiplomaSerie,
                    DiplomaNumber = skillImprovement.DiplomaNumber,
                    IssueDate = skillImprovement.IssueDate,
                    Employee = skillImprovement.Employee.ID
                };

                IEnumerable<SkillImprovement> query = (from cr in mdb.SkillImprovement
                                                       where cr.Employee == skillImprovement.Employee.ID
                                                       select cr
                                                   ).ToList();
                mdb.SkillImprovement.DeleteAllOnSubmit(query);
                mdb.SkillImprovement.InsertOnSubmit(skillImprovement1);
            }
            mdb.SubmitChanges();
        }
    }
}
